#pragma once

#include <pthread.h>
#include "mutex.h"
#include "noncopyable.h"

namespace utils
{
class Condition : noncopyable 
{
    private:
        pthread_cond_t cond;
        MutexLock& mutex;
    public:
        explicit Condition(MutexLock& mutex_) : mutex(mutex_)
        {
            pthread_cond_init(&cond, nullptr);
        }
        ~Condition()
        {
            pthread_cond_destroy(&cond);
        }
        void Wait()
        {
            pthread_cond_wait(&cond, mutex.GetPthreadMutex());
        }
        void Notify()
        {
            pthread_cond_signal(&cond);

        }
        void NotifyAll()
        {
            pthread_cond_broadcast(&cond);
        }
};
}